package com.xiaoshuidi.cloud.module.contract.controller.app.contract;

import com.xiaoshuidi.cloud.framework.common.exception.ServiceException;
import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.module.contract.controller.app.contract.vo.AuthApplyReqVO;
import com.xiaoshuidi.cloud.module.contract.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.contract.service.auth.UserAuthService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.error;
import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

/**
 * @Description:
 * @author: zhaoyu
 * @date: 2023/4/25
 */
@Tag(name = "APP - 实名认证")
@RestController
@RequestMapping(ApiConstants.NAME + "/app/auth")
@Validated
public class AppAuthController {
    @Resource
    private UserAuthService userAuthService;

    @PostMapping("/faceAuth")
    @PermitAll
    @Operation(summary = "人脸认证")
    public CommonResult<String> faceAuth(@Valid @RequestBody AuthApplyReqVO reqVO) {
        try {
            String faceAuthUrl = userAuthService.applyFaceAuth(reqVO);
            return success(faceAuthUrl);
        }  catch (ServiceException e) {
            return error(e.getCode(),e.getMessage());
        }
    }

}
